{% extends "base.html" %}
{% block head %}
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='css/rule.css') }}">
{% endblock %}
{% block content %}
<div class="container">
    <h1>Rule</h1>
    <div>
      <ul>
        <li>
        <h3>Handle: {{ rule.handle }}</h3>
        </li>
        <li>
        <h3>Family: {{ rule.table().family }}</h3>
        </li>
        <li>
        <h3>Table: {{ rule.table().name }}</h3>
        </li>
        <li>
        <h3>Chain: {{ rule.chain.name }}</h3>
        </li>
        <li>
          <h3>Description: {{ rule.description or "" }} </h3><button onclick="window.location.href='/rules/{{ rule.id }}/edit_description'">Edit Description</button>
        </li>
      </ul>
    </div>
    </div>
    <div class="espaciado">
    <h1>Statements</h1>
        <table class="table personal-table">
                <thead>
                  <tr>
                    <th>SRC</th>
                    <th>DST</th>
                    <th>SRC PORT</th>
                    <th>DST PORT</th>
                    <th>INPUT INTERFACE</th>
                    <th>OUTPUT INTERFACE</th>
                    <th>PROTOCOL</th>

                  </tr>
                </thead>
                <tbody>
                    {% for statement in statements %}
                    {% if statement.rule_id == rule.id %}
                      <tr>
                      {% if statement.src_ip != None %}
                      <td>{{ statement.src_ip }}</td>
                      {% else %}
                      <td>No source IP</td>
                      {% endif %}
                      {% if statement.dst_ip != None %}
                      <td>{{ statement.dst_ip }}</td>
                      {% else %}
                      <td>No destination IP</td>
                      {% endif %}
                      {% if statement.src_port != None %}
                      <td>{{ statement.src_port }}</td>
                      {% else %}
                      <td>No source port</td>
                      {% endif %}
                      {% if statement.dst_port != None %}
                      <td>{{ statement.dst_port }}</td>
                      {% else %}
                      <td>No destination port</td>
                      {% endif %}
                      <td>{{ statement.input_interface or "" }}</td>
                      <td>{{ statement.output_interface or "" }}</td>
                      <td>{{ statement.protocol or "" }}</td>

                    </tr>
                    {% endif %}
                    {% endfor %}
                </tbody>
              </table>
              <h1>Terminal Actions</h1>
              <table class="table personal-table">
                <thead>
                  <tr>
                    <th>reject</th>
                    <th>drop</th>
                    <th>accept</th>
                    <th>queue</th>
                    <th>return_</th>
                    <th>jump</th>
                    <th>go_to</th>

                  </tr>
                </thead>
                <tbody>
                  {% for statement in statements %}
                  <tr>
                  {% if statement.rule_id == rule.id %}
                  <td>{{ statement.reject or "" }}</td>
                  <td>{% if statement.drop %}
                  <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check" viewBox="0 0 16 16">
                    <path d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425z"/>
                  </svg>
                  {% endif %}

                  </td>
                  <td>{% if statement.accept %}
                  <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check" viewBox="0 0 16 16">
                    <path d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425z"/>
                  </svg>
                  {% endif %} 

                  </td>
                  <td>{{ statement.queue or ""}}</td>
                  <td>{% if statement.return_ == 1 %}
                  <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check" viewBox="0 0 16 16">
                    <path d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425z"/>
                  </svg>
                  {% elif statement.return_ %}
                  {{ statement.return_ }}
                  {% endif %}
                  </td>
                  <td>{{ statement.jump or ""}}</td>
                  <td>{{ statement.go_to or "" }}</td>
                  {% endif %}
                  </tr>
                  {% endfor %}
                </tbody>
              </table>
              <h1>Not terminal Actions</h1>
              <table class="table personal-table">
                <thead>
                  <tr>
                    <th>limit</th>
                    <th>log</th>
                    <th>counter</th>
                    <th>masquerade</th>
                    <th>snat</th>
                    <th>dnat</th>
                    <th>redirect</th>
                  </tr>
                </thead>
                <tbody>
                  {% for statement in statements %}
                  <tr>
                  {% if statement.rule_id == rule.id %}
                  <td>{{ statement.limit or ""}}</td>
                  <td>{{ statement.log or ""}}</td>
                  <td>{{ statement.counter or "" }}</td>
                  <td>
                  {% if statement.masquerade %}
                  <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check" viewBox="0 0 16 16">
                    <path d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425z"/>
                  </svg>
                  {% endif %}
                  </td>
                  <td>{{ statement.snat or "" }}</td>
                  <td>{{ statement.dnat or ""}}</td>
                  <td>{{ statement.redirect or ""}}</td>
                  {% endif %}
                  </tr>
                  {% endfor %}
                </tbody>
              </table>
              
    </div>

{% endblock %}              